import java.io.*;
import java.util.Scanner;

public class Demo11 {
    //进⾏普通⽂件的复制
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入源文件路径：");
        String srcPath = scanner.next();
        System.out.println("请输入目标文件路径：");
        String destPath = scanner.next();
        File srcFile = new File(srcPath);
        if (!srcFile.isFile()){
            System.out.println("该文件不存在或不是文件");
            return;
        }
        File desFile = new File(destPath);

        if (!desFile.getParentFile().isDirectory()){
            System.out.println("目标文件所在目录不存在");
            return;
        }

        try(InputStream inputStream = new FileInputStream(srcFile);
            OutputStream outputStream = new FileOutputStream(desFile)){
            while (true){
                byte[] b = new byte[1024];
                int n = inputStream.read(b);
                while (n == -1){
                    return;
                }

                outputStream.write(b,0,n);
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
